package com.example.shardingdemo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.shardingdemo.entity.AppointRecordDO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 预约记录订单 Mapper 接口
 * </p>
 *
 * @author Jin
 * @since 2021-03-27
 */
public interface AppointRecordMapper extends BaseMapper<AppointRecordDO> {

    @Select("select car.*\n" +
            "from ct_appoint_record car\n" +
            "         join ct_appoint_visitor cav\n" +
            "              on car.id = cav.record_id\n" +
            "where\n " +
            "      to_days(car.reservation_date) = to_days(NOW())" +
            "      and car.scenic_id = '${scenicId}'\n" +
            "      and cav.certificate_code = '${certificateCode}'\n" +
            "      and car.state != -1 " +
            " group by car.id")
    @ResultMap("BaseResultMap")
    List<AppointRecordDO> getTodayAppointRecord(@Param("scenicId") String scenicId, @Param("certificateCode") String certificateCode);

    @Select("select car.*\n" +
            "from ct_appoint_record car\n" +
            "         join ct_appoint_visitor cav\n" +
            "              on car.id = cav.record_id\n" +
            "where\n " +
            "      to_days(car.reservation_date) = to_days(CURDATE()+1)" +
            "      and car.scenic_id = '${scenicId}'\n" +
            "      and cav.certificate_code = '${certificateCode}'\n" +
            "      and car.state != -1 " +
            " group by car.id")
    @ResultMap("BaseResultMap")
    List<AppointRecordDO> getNextDayAppointRecord(@Param("scenicId") String scenicId, @Param("certificateCode") String certificateCode);

}